﻿@{
    Layout = null;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>测试服务器状态</title>
    <script src="../../scripts/jquery-1.4.4.min.js" type="text/javascript"></script>
    <link href="../../Content/css/style.css" rel="stylesheet" type="text/css" />
    <script src="../../scripts/jquery.jsonp-2.3.0.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        function getDate() {
            var d, s, t;
            d = new Date();
            s = d.getFullYear().toString(10).slice(-2) + "-";
            t = d.getMonth() + 1;
            s += (t > 9 ? "" : "0") + t + "-";
            t = d.getDate();
            s += (t > 9 ? "" : "0") + t + " ";
            t = d.getHours();
            s += (t > 9 ? "" : "0") + t + ":";
            t = d.getMinutes();
            s += (t > 9 ? "" : "0") + t + ":";
            t = d.getSeconds();
            s += (t > 9 ? "" : "0") + t;
            return s;
        }
        //错误上限
        errCount = 0;
        timers = 0;
        //检测IIS与DB
        function checkModuleIIS(name, url) {
            $.jsonp({
                type: "GET",
                dataType: "jsonp",
                cache: false,
                url: url,
                timeout: 10000,
                callbackParameter: 'jsonpcallback',
                success: function (data) {
                    var iismsg = "";
                    var sqlmsg = "";
                    if (data.IISMessage == "Fail") {
                        iismsg = "<font color=red>IIS错误</font>";
                        errCount++;
                    }
                    else {
                        iismsg = "<font color=green>OK</font>";
                    }
                    if (data.DBMessage == "Fail") {
                        sqlmsg = "<font color=red>数据库错误</font>";
                        errCount++;
                    }
                    else if (data.DBMessage == "NoSql") {
                        sqlmsg = "<font color=blue>没有数据库</font>";
                    }
                    else {
                        sqlmsg = "<font color=green>OK</font>";
                    }
                    $("#serverName" + name).html(data.ServerName);
                    $("#serverIP" + name).html(data.ServerIP);
                    $("#iis" + name).html(iismsg);
                    $("#db" + name).html(sqlmsg);
                    $("#time" + name).html(getDate());
                },
                error: function (xOptions, textStatus) {
                    errCount++;
                    $("#serverName" + name).html(url);
                    $("#serverIP" + name).html(xOptions.ServerIP);
                    $("#iis" + name).html("<font color=red>IIS错误</font>");
                    $("#db" + name).html("<font color=red>数据库错误</font>");
                    $("#time" + name).html(getDate());
                }
            });
        }
        // 测试服务器1
        function checkFun() {
            remove_embedFun();
            $(".list>table>tbody>tr").each(function (a, b) {
                checkModuleIIS($(this).find("input[name=ServerID]").val(), $(this).find("input[name=ServerUrl]").val());
            });
            setTimeout("checkFun()", 10 * 1000);
        }

        //时钟
        function timerFun() {
            timers++;
            if (timers >= 60) {
                timers = 0;
                errCount = 0;
            }
            else {
                if (errCount >= 3) {
                    if ($("body").find("embed").length == 0 && $("body").find("bgsound").length == 0) {
                        $("body").append('\
                                            <embed src="/content/BUZZ5.WAV" width="145" height="55" autostart="true" loop="false"  /> \
                                            <noembed> \
                                            <bgsound src="/content/BUZZ5.WAV" loop="1"> \
                                            </noembed>\
                                            ');
                    }

                }
            }
            $('#timer').html(getDate());
            setTimeout("timerFun()", 1000)
        }

        //删除播放器
        function remove_embedFun() {
            $("embed").remove();
            $("noembed").remove();
        }
        // 调用测试方法
        $(function () {
            $("#tablist").attr("width", screen.width - 10);
            if (screen.width <= 800) {
                $("#tablist").attr("width", 220);
                $(".ip").hide();
                $(".updatetime").hide();
            }
            checkFun();
            setTimeout("timerFun()", 1000)

        });
    </script>
</head>
<body style="text-align: center">
    <!--banner区-->
    <!--msg区-->
    <div class="msg" style="width: 100%">
        时间：<span id="timer"></span>&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: Red; font-weight: bold;">
            [
            @{
                int timeflag = 1;
                if (DateTime.Now.Hour >= 8 && DateTime.Now.Hour < 14)
                {
                    timeflag = 0;
                }

                var user = (ViewBag.UserConfig as List<TestClient.Models.User>)
                    .FirstOrDefault(i =>
                       i.WorkDate == DateTime.Now.Date
                       && i.Screenings == timeflag);

                if (user != null)
                {
                    Write("职班工程师:"
                        + user.Name
                        + "，电话："
                        + user.Tel
                        + "，场次："
                        + (user.Screenings == 0 ? "上午(8:00~14:00)" : "下午(14:00~20:00)"));

                }
                else
                {
                    Write("无人职班");
                }
            }
            ]</span>
    </div>
    <div class="clear">
    </div>
    <!--list区-->
    <div class="list">
        <table id="tablist" border="0" cellpadding="0" cellspacing="0">
            <thead>
                <tr class="list_tit">
                    <td class="servername">
                        网站名称
                    </td>
                    <td class="ip">
                        IP地址
                    </td>
                    <td class="iis">
                        IIS
                    </td>
                    <td class="db">
                        数据库
                    </td>
                    <td class="updatetime">
                        更新时间
                    </td>
                </tr>
            </thead>
            <tbody>
                @foreach (var i in ViewBag.ServerConfig as List<TestClient.Models.ServerStruct>)
                {  
                    <tr class="list_tit_con">
                        <input type="hidden" value="@i.ServerUrl" name="ServerUrl"/>
                        <input type="hidden" value="@i.ServerID" name="ServerID"/>
                        <td style="text-align:left" id="serverName@(i.ServerID)" class="servername">
                        </td>
                        <td  class="ip" id="serverIP@(i.ServerID)">
                        </td>
                        <td class="iis" id="iis@(i.ServerID)">
                        </td>
                        <td class="db" id="db@(i.ServerID)">
                        </td>
                        <td class="updatetime" id="time@(i.ServerID)">
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
    <div class="clear">
    </div>
    <div class="footer">
        清大世纪 技术部</div>
    <div class="clear">
    </div>
</body>
</html>
